import { getStore } from '@/utils/store'

const organizationInfo = getStore('organizationInfo') || {}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '合同编号',
			prop: 'contractNumber',
			type: 'text',
			span: 12,
			rules: [{ required: true, message: '请输入合同编号' }],
		},
		{
			label: '关联方式',
			prop: 'bindType',
			type: 'radio',
			rules: [{ required: true, message: '请选择关联方式' }],
			dicData: [
				{
					label: '直营',
					value: 1,
					type: 'success',
				},
				{
					label: '加盟',
					type: 'danger',
					value: 2,
				},
			],
			span: 12,
		},
		{
			label: '开始时间',
			prop: 'startTime',
			type: 'date',
			format: 'YYYY年MM月DD',
			valueFormat: 'YYYY-MM-DD',
			span: 12,
			rules: [{ required: true, message: '请选择开始时间' }],
		},
		{
			label: '结束时间',
			prop: 'endTime',
			type: 'date',
			format: 'YYYY年MM月DD',
			valueFormat: 'YYYY-MM-DD',
			span: 12,
			rules: [{ required: true, message: '请选择结束时间' }],
		},
		{
			label: organizationInfo.type == 4 ? '选择助餐点' : '选择中心厨房',
			prop: 'soleValue',
			propName: 'soleValue',
			type: 'autoSelect',
			api: 'dpServiceFacility_page',
			filterKey: 'soleValue',
			filterLabel: 'soleValue',
			paramsObj: {
				isWithAuth: 0,
				type: organizationInfo.type == 4 ? 11 : 4,
			},
			multiple: false,
			display: organizationInfo.type ? true : false,
			rules: [{ required: true, message: '请选择' }],
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '中心厨房名称',
			prop: 'centralKitchen',
			type: 'input',
			span: 8,
		},

		{
			label: '助餐点名称',
			prop: 'mealStation',
			type: 'input',
			span: 8,
		},
		{
			label: '关联方式',
			prop: 'bindType',
			type: 'select',
			span: 8,
			dicData: [
				{
					label: '直营',
					value: 1,
					type: 'success',
				},
				{
					label: '加盟',
					type: 'danger',
					value: 2,
				},
			],
		},
		{
			label: '合同编号',
			prop: 'contractNumber',
			type: 'input',
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '中心厨房名称', prop: 'centralKitchen' },
		{ label: '助餐点名称', prop: 'mealStation' },
		{
			label: '关联方式',
			prop: 'bindType',
			custome: 'tag',
			dicData: [
				{
					label: '直营',
					value: 1,
					type: 'success',
				},
				{
					label: '加盟',
					type: 'danger',
					value: 2,
				},
			],
		},
		{ label: '合同编号', prop: 'contractNumber' },
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omMealBind_page',
	add: 'view_omMealBind_add',
	edit: 'view_omMealBind_edit',
	delete: 'view_omMealBind_del',
	detail: 'view_omMealBind_view',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '中心厨房直营_加盟助餐点',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'contractNumber',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
	operateFormate: async (row, type) => {
		return new Promise((resolve, reject) => {
			const tempRow = {
				...row,
				soleValue: organizationInfo.type == 4 ? row.mealStation : row.centralKitchen,
			}
			resolve(tempRow)
		})
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			if (organizationInfo.type == 4) {
				form.centralKitchen = organizationInfo.organizationName
				form.mealStation = form.soleValue
			} else {
				form.mealStation = organizationInfo.organizationName
				form.centralKitchen = form.soleValue
			}
			resolve(form)
		})
	},
}
